﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class OldLeagueTables : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.OldLeagueTables_PageTitle;
            //if (!HttpContext.Current.User.Identity.IsAuthenticated)
            //    Response.Redirect("Default.aspx");
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            
            //this.Title = GND.ReturnAppTitle();
            this.PageNameLabel.Text = GND.ReturnAppTitle();
            
            //if (ou.TeamId == "Null")
            //    Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");

            string LeagueId = null;
            string Season = null;

            if (Request.QueryString["Season"] != null)
                Season = Request.QueryString["Season"].ToString();
            else
                Season = "0";
            if (Request.QueryString["LeagueId"] != null)
                LeagueId = Request.QueryString["LeagueId"].ToString();
            if (LeagueId == null)
                Response.Redirect("GeneralMessage.aspx?MessageString=l4OF1EOTHJA");
            else
            {
                LeagueIdHiddenField.Value = LeagueId;
                if (!IsPostBack)
                {
                    this.SqlDataSource1.SelectParameters.Add("LeagueId", LeagueId);
                    this.SqlDataSource1.SelectParameters.Add("Language", ou.Language);
                    this.SqlDataSource2.SelectParameters.Add("LeagueId", LeagueId);
                    this.SqlDataSource2.SelectParameters.Add("Season", Season);
                    this.SqlDataSource5.SelectParameters.Add("LeagueId", LeagueId);
                    this.SqlDataSource5.SelectParameters.Add("Language", ou.Language);
                }
            }

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string LeagueId = null;
            LeagueId = Request.QueryString["LeagueId"].ToString();
            Response.Redirect("OldLeagueTables.aspx?LeagueId=" + LeagueId + "&Season=" + SeasonDropDownList.SelectedValue);
        }

        protected System.Drawing.Color GDColumnColor(Object RowNum)
        {
            string LeagueId = LeagueIdHiddenField.Value;
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            if (!GND.ReadNivdalBoolData("@LeagueId", "Nivdal_IsLastLeagueLevel", LeagueId))
            {

                if (RowNum.ToString() == "1")
                    return System.Drawing.Color.Green;
                if (RowNum.ToString() == "2")
                    return System.Drawing.Color.LightGray;
                if (RowNum.ToString() == "3")
                    return System.Drawing.Color.White;
                if (RowNum.ToString() == "4")
                    return System.Drawing.Color.LightGray;
                if (RowNum.ToString() == "5")
                    return System.Drawing.Color.White;
                if (RowNum.ToString() == "5")
                    return System.Drawing.Color.White;
                if (RowNum.ToString() == "6")
                    return System.Drawing.Color.LightGray;
                if (RowNum.ToString() == "7")
                    return System.Drawing.Color.White;
                else if (RowNum.ToString() == "8")
                    return System.Drawing.Color.Red;
                else if (RowNum.ToString() == "9")
                    return System.Drawing.Color.Red;
                else if (RowNum.ToString() == "10")
                    return System.Drawing.Color.Red;
                else
                    return System.Drawing.Color.Empty;
            }
            else
            {
                return System.Drawing.Color.Empty;
            }
        }

        protected bool RedVisible(object N)
        {
            if ((N.ToString() == "8") || (N.ToString() == "9") || (N.ToString() == "10"))
                return (true);
            return (false);

        }

        protected bool GreenVisible(object N)
        {
            if (N.ToString() == "1")
                return (true);
            return (false);
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}